<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%	
String sysUserId = request.getParameter("sysUserId");
request.setAttribute("sysUserId",sysUserId); 
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body,html {
	margin: 0 auto;
	height: 100%;
	width: 100%;
}

input {
	border: 1px solid #9ABAE9;
	windth: 150px;
	height: 18px;
}

textarea {
	border: 1px solid #9ABAE9;
	windth: 135px;
	height: 50px;
}
</style>
</head>
<body>
	<div id="user_role_add" style="width: 100%; height: 100%;" class="divfrist">
		<div style="width: 100%; height: 0.7%; overflow: hidden;"></div>
		<div style="width: 100%; height: 98.6%;">
			<div style="width: 0.4%; height: 100%; float: left; overflow: hidden;"></div>
			<div style="width: 99.2%; height: 100%; float: left;">
				<div class="allborder" style=" overflow: auto; height: 100%; max-height: 100%;margin-left:-1px;">
					<!--内容区 -->
							<div style="width:100%;height:100%;">		
								<table  id="user_role_addTable"></table>
									<div id="user_role_addTb" style="overflow: hidden;">
												 <div style="height:25px;"><span style="line-height: 18px;height:30px;"> 当前用户已有角色：<span id="roleText"></span></span></div>
												
												 <a href="javascript:void(0);" class="easyui-linkbutton"   data-options="iconCls:'icon632',plain:true" onclick="window.user_role.userroleadd()">附加角色</a>||[注:每次增加角色都全部在次授权,支持多页连续勾选] 	    	
									</div>
							</div>
										
					<!--内容区 -->
				</div>
			</div>
			<div class="width:0.35%;height:100%;float:left;overflow:hidden;"></div>
		</div>
		<div class="width:100%;height:0.6%;overflow:hidden;"></div>
	</div>
</body>
<script type="text/javascript">
(function(){
	function userroleadd(){
		var rows = $("#user_role_addTable").datagrid("getSelections");
		if(rows.length<=0){
			alert("没有选中数据");
			return;
		}
		$.messager.confirm('提示', '你确定要为用户附加这些权限吗?', function(r){
			if (r){
				$.ajax({
					   type: "POST",
					   url:'${pageContext.request.contextPath}/sys/sysUserAction!userRoleadd.action',
					   data:{rows1:obj2str(rows),sysUserId:"${sysUserId}"},
					   dateType:'text',
					   success: function(msg){
					    	if(msg=="success"){
					    		alert("操作成功");
					    	}else{
					    		alert("操作失败");
					    	}
					   },error:function(a,b,c){
						   alert("错误");
					   }
					});
			}
		});
	}
	//增加一个角色的table
	function createUser_role_addTable(){
		$('#user_role_addTable').datagrid({
			fit: true,
			toolbar:"#user_role_addTb",
			singleSelect:false,
			queryParams:{},
			rownumbers: true,
			animate:true,
			border:false,
			striped: true,
			loadMsg:'正在加载数据',
			url: "${pageContext.request.contextPath}/sys/sysRoleAction!getRoleList.action",
			collapsible:true,
			idField:'roleId',
			fitColumns:true,
			columns:[[
			    {field:'roleId',checkbox:true,width:50},	
		  		{field:'roleName',title:'角色名称',width:120},
		  		{field:'roleState',title:'角色状态',formatter : function(value, row, index){
					if(row.roleState=="0"){
						return  '<font color="red">禁用</font>';
					}
					if(row.roleState=="1"){
						return  '<font color="green">启用</font>';
					}
					return "";
					},width:120},
		  		{field:'roleNote',title:'角色描述',width:120},
		  		{field:'roleCreateDate1',title:'创建时间',width:120}
		  		]],
				pagination:true
			});
		
	}
	//查询当前用户已经有的角色
	function selectUserRole(){
		
		if("${sysUserId}"==""||"${sysUserId}"==null){
			alert("没有角色提供查询");
			return;
		}
		$.ajax({
			   type: "POST",
			   url:'${pageContext.request.contextPath}/sys/sysUserAction!selectUserRole.action',
			   data: {sysUserId:"${sysUserId}"},
			   dataType:'json',
			   success: function(msg){
				   $("#roleText").text("");
					if(msg.length>=0){
						for(var i=0;i<msg.length;i++){								
							 $("#roleText").append("<font color='red'>["+msg[i].roleName+"]</font>")
						}
					}
			   }
		});
	}
	//注册所有事件
	window["user_role"]={};
	window["user_role"]["userroleadd"]=userroleadd;
	$(function(){	
		$.parser.parse('#user_role_add'); 
		createUser_role_addTable();
		selectUserRole();
	});
	
})();
</script>
</html>